/**
 * 
 */

/**
 * @author kdlucas
 *
 */

import java.lang.*;

public class ScheduleAnalyzer {
	
	private String flightNum;
	private String origin;
	private String destination;
	private int weatherOrigin;
	private int weatherDest;
	private int flightSchedule;  //flightSchedule of 0 means flight is on time. 
	                             // negative values means it's early.
	                             // positive values means minutes running late.
	                             // A special value of -1 means the flight is
	                             // cancelled.
    private int historicalTakeoffTime;
    private int historicalArrivalTime;
	private int takeoffTime;
    private int arrivalTime;
	
	public ScheduleAnalyzer(String newFlightNum, String newOrigin, String newDest) {
		setFlightNum(newFlightNum);
		setOrigin(newOrigin);
		setDestination(newDest);
		weatherOrigin = 0;
		weatherDest = 0;
		flightSchedule = 0;
		takeoffTime = 0;
		arrivalTime = 0;
		historicalTakeoffTime = retrieveHistoricalTakeoffTime();
		historicalArrivalTime = retrieveHistoricalArrivalTime();
	}
	
	public void setFlightNum(String newFlightNum) {
		flightNum = newFlightNum;
	}
	
	public String getFlightNum() {
		return flightNum;
	}
	
	public void setOrigin(String newOrigin) {
		origin = newOrigin;
	}
	
	public String getOrigin() {
		return origin;
	}
	
	public void setDestination(String newDestination) {
		destination = newDestination;
	}
	
	public String getDestination() {
		return destination;
	}
	
	public void setWeatherOrigin(int i) {
		weatherOrigin = i;
	}
	
	public void setWeatherDest(int i) {
		weatherDest = i;
	}
	
	public void setFlightSchedule(int i) {
		flightSchedule = i;
	}
	
	public int getWeatherOrigin() {
		return weatherOrigin;
	}
	
	public int getWeatherDest() {
		return weatherDest;
	}
	
	public int getFlightSchedule() {
		return flightSchedule;
	}
	
	public void setHistoricalTakeoffTime(int i) {
		historicalTakeoffTime = i;
	}
	
	public int getHistoricalTakeoffTime() {
		return historicalTakeoffTime;
	}

	public void setHistoricalArrivalTime(int i) {
		historicalArrivalTime = i;
	}
	
	public int getHistoricalArrivalTime() {
		return historicalArrivalTime;
	}
	
	public int retrieveHistoricalTakeoffTime() {
		// Eventually this will be retrieved from our database.
		// For now we will fill this with mock data.
		return 10;
	}
	
	public int retrieveHistoricalArrivalTime() {
		// Eventually this will be retrieved from our database.
		// For now we will fill this with mock data.
		return 20;
	}
	
	public int getTakeOffTime() {
		// This method will return 0 if take off time is not altered from the 
		// original flight schedule. Otherwise it will return a positive or 
		// negative number, depending on if the flight is targeted to leave
		// early (negative number) or late. -1 is a special case which means
		// the flight is cancelled.
		
		int timeFactor = 0;
		
		// Be aware that if setWeatherOrigin and setFlightSchedule have not been called,
		// then the computation will be meaningless.
		
		timeFactor = computeWeatherAffects(weatherOrigin);
		if (timeFactor == -1 || flightSchedule == -1) {
			return -1;
		}
		timeFactor = timeFactor + flightSchedule + historicalTakeoffTime;
		takeoffTime = timeFactor;
		return timeFactor;
	}
	
	public int getArrivalTime() {
		// This method will return 0 if landing time is not altered from the
		// original schedule. Otherwise a positive or negative number will be
		// returned, which represents the number of minutes the flight will
		// deviate from it's original schedule. -1 is a special case which means
		// their was an error 
		
		int timeFactor = 0;
		
		// Be aware the if setWeatherDest and setFlightSchedule have not been set,
		// then the computation will be meaningless.
		
		timeFactor = computeWeatherAffects(weatherDest);
		if (timeFactor == -1 || flightSchedule == -1) {
			return -1;
		}
		
		timeFactor = timeFactor + flightSchedule + takeoffTime + historicalArrivalTime;
		arrivalTime = timeFactor;
		return timeFactor;
	}
	
	public int computeWeatherAffects(int intensity) {
		// intensity is rated from 0 to 6, with 6 being the worst weather condition.
		// If minutes is set to -1, it means the flight is cancelled.
		int minutes = 0;
		
		switch (intensity) {
		case 0:
			minutes = 0;
			break;
		case 1:
			minutes = 20;
			break;
		case 2:
			minutes = 30;
			break;
		case 3:
			minutes = 45;
			break;
		case 4:
			minutes = 60;
			break;
		case 5:
			minutes = 120;
			break;
		case 6:
			minutes = -1;
			break;
		}
		
		return minutes;
	}
	
	public static void main(String []args) {
		ScheduleAnalyzer scheduler = new ScheduleAnalyzer("TestFlight114", "Dallas", "New York");
		scheduler.setWeatherDest(1);
		scheduler.setFlightSchedule(30);
		scheduler.setWeatherOrigin(1);
		scheduler.getTakeOffTime();
		scheduler.getArrivalTime();
		
		System.out.format("The projected take off time is %d minutes from the scheduled time.%n",
				scheduler.takeoffTime);
		System.out.format("The projected landing time is %d minutes from the scheduled time.%n",
				scheduler.arrivalTime);
	}
}
